$(function () {
  // 登录功能
  $(".login").click(function () {
    var name = $(".login-name").val();
    var key = $(".login-key").val();
    if (name != '' && key != '') {
      $.ajax({
        url: "http://ce.shi/login/",
        type: "post",
        data: {
          name: name,
          key: key
        },
        dataType: "JSON",
        cache: false, //同步请求
        ContentType: "application/xml;charset=utf-8",
        success: function (res) {
          console.log(res)
          //将token存储到本地
          if (!window.localStorage) {
            alert("浏览器不支持localstorage");
            return false;
          } else {
            //将token存入本地并且进行网页跳转
            var storage = window.localStorage;
            storage["token"] = res.token;
            // window.location.href = "http://wu.an/index.html";
          } 
        },
        error:function(err){
          console.log('登录失败')
        }
      });
    } else {
      alert("用户名或密码不能为空")
    }
  })
})